package com.kafka.consumer;

import com.alibaba.fastjson.JSON;
import com.kafka.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @author 顾志杰
 * @date 2020/8/10-9:43
 */
@Component
@Slf4j
public class ConsumerService {


    public ConsumerService() {
    }

    @KafkaListener(groupId = "group02", topics = "topic03")
    public void onMessage(ConsumerRecord<String, Object> record, Acknowledgment acknowledgment, Consumer<?, ?> consumer) {
        User value = JSON.parseObject(String.valueOf(record.value()),User.class);
        log.info("消费端接收消息：{}", value.toString());
        /*手工签收*/
       acknowledgment.acknowledge();
    }

}
